<?php
// truncate table 

// 计算 某一天的 总营业额
SELECT 
  SUM(need_to_pay) AS total 
FROM
( SELECT 
  need_to_pay,pay_time
FROM
  `order`
GROUP BY id HAVING pay_time>'2017-04-19'  ) AS c 

// 查询某个用户的日志记录
SELECT 
  * 
FROM
  `log` 
WHERE TYPE = 1 
  AND link_id = 2 

// 商品 销量 排行
SELECT 
  odr.sku,
  c.name,
  odr.price,
  SUM(odr.cnt) AS num,
  odr.price*SUM(odr.cnt) AS total
FROM
  `order_detail` odr
  LEFT JOIN com c ON c.id=odr.sku
GROUP BY odr.sku 
ORDER BY num DESC ,total DESC